package com.example.wac.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author wuancheng
 * @description
 * @date 2022-05-05 15:07:00
 */

@Slf4j
// @Order(1)表示执行顺序，值越小，越先执行
@Order(1)
// urlPatterns过滤器要过滤的URL规则配置，filterName过滤器的名称。
@WebFilter(urlPatterns = "/*",filterName = "MyFilter")
@Component
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 程序启动时加载
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 拦截器放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        // 程序结束时销毁
    }
}
